package com.authine.cloudpivot.ext.dto;

import com.authine.cloudpivot.ext.utils.BigDecimalUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Data
@Schema(description = "ContractGoodsDto")
@ApiModel("代购商品表")
public class ContractGoodsDto {
    @Schema(description = "代购商品ID")
    private String id;
    @Schema(description = "代购意向ID")
    private String contractIntentionId;
    @Schema(description = "名称")
    private String name;
    @Schema(description = "品牌")
    private String brand;
    @Schema(description = "型号")
    private String model;
    @Schema(description = "规格")
    private String spec;
    @Schema(description = "税前单价")
    private BigDecimal pretaxPrice;
    @Schema(description = "单价")
    private BigDecimal price;
    @Schema(description = "数量")
    private BigDecimal num;
    @Schema(description = "单位")
    private String unit;
    @Schema(description = "小计")
    private BigDecimal total;
    @Schema(description = "备注")
    private String memo;
    @Schema(description = "删除")
    private String del;
    @Schema(description = "操作人")
    private String operator;
    @Schema(description = "税率")
    private BigDecimal taxRate;

    public static Map<String, Object> voToEntity(ContractGoodsDto dto) {
        Map<String, Object> result = new HashMap<>();
        result.put("id", dto.getId());
        result.put("contract_intention_id", dto.getContractIntentionId());
        result.put("name", dto.getName());
        result.put("brand", dto.getBrand());
        result.put("model", dto.getModel());
        result.put("memo", dto.getMemo());
        result.put("spec", dto.getSpec());
        result.put("pretax_price", dto.getPretaxPrice());
        result.put("price", dto.getPrice());
        result.put("num", dto.getNum());
        result.put("unit", dto.getUnit());
        result.put("total", dto.getTotal());
        result.put("memo", dto.getMemo());
        result.put("del", !Objects.isNull(dto.getDel())&&dto.getDel().equals("1")?true:false);
        result.put("operator", dto.getOperator());
        result.put("tax_rate", BigDecimalUtils.round(dto.getTaxRate(), 2));
        return result;
    }
}
